//
//  TTGoodsDetailParamsView.m
//  TaoTuo
//
//  Created by LG on 2020/11/17.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTGoodsDetailParamsView.h"
#import <UIView+TYAlertView.h>
#import "TTGoodsDetailInfoViewCell.h"

@interface TTGoodsDetailParamsView ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIButton *knowBtn;
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation TTGoodsDetailParamsView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.dataArray = [NSMutableArray array];
        [self setupSubviews];
        
        
    }
    return self;
}


- (void)show
{
    self.transform = CGAffineTransformIdentity;
    [self showInController:[LLRouteTool getRootViewController] preferredStyle:TYAlertControllerStyleActionSheet backgoundTapDismissEnable:YES];
}

- (void)dismiss
{
    [self hideView];
}

- (void)setModel:(TTDetailModel *)model
{
    _model = model;
    
    [self.dataArray removeAllObjects];
    
    [self.dataArray addObject:[TTGoodsDetailInfoModel setModelWithTitle:@"成色" content:model.GoldColor]];
    [self.dataArray addObject:[TTGoodsDetailInfoModel setModelWithTitle:@"货品分类" content:self.model.CategoryName]];
    [self.dataArray addObject:[TTGoodsDetailInfoModel setModelWithTitle:@"工费" content:model.WorkTotalPrice]];
    [self.dataArray addObject:[TTGoodsDetailInfoModel setModelWithTitle:@"损耗" content:model.GoldLoss]];
    [self.dataArray addObject:[TTGoodsDetailInfoModel setModelWithTitle:@"款式镶法" content:model.StyleSettingName]];
    [self.dataArray addObject:[TTGoodsDetailInfoModel setModelWithTitle:@"爪数/叶数" content:model.ClawNumber]];
    [self.dataArray addObject:[TTGoodsDetailInfoModel setModelWithTitle:@"加工工艺" content:model.Technology]];
    [self.dataArray addObject:[TTGoodsDetailInfoModel setModelWithTitle:@"款式风格" content:model.LargeStyles]];
    [self.dataArray addObject:[TTGoodsDetailInfoModel setModelWithTitle:@"颈部造型" content:model.NeckModeling]];
    [self.dataArray addObject:[TTGoodsDetailInfoModel setModelWithTitle:@"颈部花头" content:model.NeckFlower]];
    [self.dataArray addObject:[TTGoodsDetailInfoModel setModelWithTitle:@"款式爪型" content:model.Alias]];
    [self.dataArray addObject:[TTGoodsDetailInfoModel setModelWithTitle:@"款式戒臂" content:model.StyleArm]];
    
    [self.tableView reloadData];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TTGoodsDetailInfoViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.model = self.dataArray[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)setupSubviews
{
    UIBezierPath *bgPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *bgLayer = [CAShapeLayer layer];
    bgLayer.path = bgPath.CGPath;
    bgLayer.fillColor = UIColor.whiteColor.CGColor;
    [self.layer addSublayer:bgLayer];
    
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(100, 37)];
    [path addLineToPoint:CGPointMake(self.width - 100, 37)];
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.lineWidth = 2;
    layer.lineDashPattern = @[@2, @3];
    layer.lineCap = kCALineCapRound;
    layer.strokeColor = UIColorHex(#999999).CGColor;
    layer.path= path.CGPath;
    [self.layer addSublayer:layer];
    
    _titleLabel = [UILabel labelWithTitle:@"参数" color:UIColorHex(#333333) font:[UIFont boldSystemFontOfSize:16]];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.backgroundColor = UIColor.whiteColor;
    [self addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(26);
        make.width.mas_equalTo(50);
        make.centerX.equalTo(self);
    }];
    
    _knowBtn = [UIButton createButtonWithTitle:@"我知道啦！" titleColor:UIColor.whiteColor titleFont:[UIFont boldSystemFontOfSize:16] backgroundColor:UIColorHex(#8B57E6) cornerRadius:20 target:self action:@selector(dismiss)];
    [self addSubview:_knowBtn];
    [_knowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(-35);
        make.centerX.equalTo(self);
        make.width.mas_equalTo(161);
        make.height.mas_equalTo(40);
    }];
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.rowHeight = 30;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_tableView registerClass:[TTGoodsDetailInfoViewCell class] forCellReuseIdentifier:@"cell"];
    [self addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
        make.left.right.equalTo(self);
        make.bottom.equalTo(self.knowBtn.mas_top).offset(-20);
    }];
    
}

@end
